package org.xfy.sys.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.xfy.base.service.impl.BaseServiceImpl;
import org.xfy.org.exception.BusinessException;
import org.xfy.base.util.ErrorCode;
import org.xfy.sys.domain.DictionaryDetail;
import org.xfy.sys.domain.DictionaryType;
import org.xfy.sys.mapper.DictionaryDetailMapper;
import org.xfy.sys.service.IDictionaryTypeService;

import java.util.List;

@Service
public class DictionaryTypeServiceImpl extends BaseServiceImpl<DictionaryType> implements IDictionaryTypeService {
    @Autowired
    private DictionaryDetailMapper dictionaryDetailMapper;

    @Override
    public void patchDel(Long[] ids) {
        for (Long id : ids) {
            List<DictionaryDetail> list = dictionaryDetailMapper.findDetailsByTypeid(id);
            if(list!=null){
                throw  new BusinessException(ErrorCode.Besiness_ERROR.getCode());
            }
        }
        super.patchDel(ids);
    }

    @Override
    @Transactional
    public void del(Long id) {
        //通过id查出所有详情
        List<DictionaryDetail> list = dictionaryDetailMapper.findDetailsByTypeid(id);
        if(list!=null){
            throw  new BusinessException(ErrorCode.Besiness_ERROR.getCode());
        }
        super.del(id);
    }
}
